next up previous
Next: 2.2 Advantages of 64-bit Up: 2 General 64-bit Considerations Previous: 2 General 64-bit Considerations

2.1 The 64-bit Programming Model

Once you have decided that you need a 64-bit version of your code, you need to consider what changes when you compile your code to generate 64-bit executables. Even if you have no immediate plans to port code to 64-bit, you should adopt the coding practices described here to avoid pitfalls in future code.

The most important difference between a 32-bit and a 64-bit system is the sizing of fundamental C data types. The source of most problems with code being recompiled for 64-bit is due to assumptions about data type sizes. So how do the size of C data types change in 64-bit?

There are a couple different answers. So far, the term ``64-bit'' has been used informally. In general, 64-bit means that pointers are represented as 64-bit valuesgif in contrast to the 32-bit pointers on 32-bit systems. While 64-bit systems use 64-bit pointers, the sizes of other C data types are open for interpretation.

The C language specification leaves it to compiler implementors to define the sizes for C data types for a particular target architecture. How many bytes make up a long, int, or short is not defined by the C language specification. The sizes of the C integer types are sized based on the target architecture's ability to efficiently implement integers of the various sizes.

  
Table 1: C data type models for 32-bit and 64-bit systems.

For 64-bit systems, there is more than one reasonable way to size the basic C data types. Table 1 lists some of the possible C data type sizes for 64-bit and 32-bit systems. The 32BIT and PC models are not 64-bit models but are listed for comparison.

The PC model is the standard for Intel's x86 architecture. The 32BIT model is the standard for 32-bit workstations. The nice thing about the 32BIT model is that the pointer, int, and long data types all share the same 32-bit representation. If you are unfamiliar with the long long data type, it is an invention of some compiler implementors to support a larger than 32-bit integer type without resizing the 32BIT long and without adding any new keywords to the C language. Not all compilers implement long long.

The LP64, LLP64, and ILP64 models are all 64-bit models. The names are mnemonic for the types that are represented as 64-bit values in each model. For example, ILP64 indicates that pointer, int, and long data types are represented as 64-bit values. Each model has advantages and disadvantages for compatibility with existing code, interoperability with 32-bit processes, functionality, and performance.

The choice of which 64-bit data type model to use is generally made by your system or C compiler vendor. Most 64-bit Unix workstation vendors are adopting the LP64 model, but be aware that other models exist. In particular, Cray uses the ILP64 model.

For floating point types, the size of the float and double type generally is 32-bit and 64-bit respectively. This is not a change from the 32BIT model. Larger than 64-bit floating pointer types are possible though.

Since the existing 64-bit X workstation vendors have adopted the LP64 model, that model is assumed for the rest of this article though many observations that follow are relevant to the other 64-bit models. The source of most 64-bit LP64 transition problems is that that the pointer and long data types are sized differently than the int data type in the 32BIT model. Existing C code written for the 32BIT model is liable to break if it is based on assumptions about the int, long, and pointer types being the same size.



next up previous
Next: 2.2 Advantages of 64-bit Up: 2 General 64-bit Considerations Previous: 2 General 64-bit Considerations



Mark Kilgard
Sat Dec 30 11:52:07 PST 1995